 
package threads;

import gui.Supervisor;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import juego.Logica;
import unidad.*;

public class ThreadMana extends Thread 
{
	protected Random gen;
	protected Random fila;
	protected Supervisor sup;
	protected boolean terminar;
	protected boolean corre;
	JLabel locura;
	
	public ThreadMana(Supervisor s)
	{
		gen = new Random();
		sup = s;
		terminar = false;
		corre=true;
	}
	
	public void run()
	{
		
		while(!terminar)
		{
				locura = new JLabel();
				sup.agregarPrisionero(locura);
				locura.addMouseListener(new MouseListener() {
					
					@Override
					public void mouseReleased(MouseEvent e) {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void mousePressed(MouseEvent e) {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void mouseExited(MouseEvent e) {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void mouseEntered(MouseEvent e) {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void mouseClicked(MouseEvent e) {
						
						locura.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/rI.gif")));
						corre=false;
						sup.modificarMana(25);
						sup.modificarPuntuacion(30);
					}
				});
				
				locura.setBounds(1050,(gen.nextInt(629)+1), 60, 50);
				locura.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/corriendoI.gif")));
				int i=0;
				corre=true;
				while ((i < 1100) && corre)
				{
					locura.setLocation((locura.getLocation().x)-1, locura.getLocation().y);
					i++;
					try {
						Thread.sleep(10);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				try {
					Thread.sleep(1500);
				} catch (InterruptedException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
				sup.quitarPrisionero(locura);
				
				
				try {
					Thread.sleep(gen.nextInt(50000));
				} catch (InterruptedException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
		}
		
	}

	public void terminar()
	{
		terminar=true;
	}
}
